// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) fieldsfirst 
// Source File Name:   r.java

package com.intellij.ide.license.impl;

import com.intellij.openapi.application.impl.ApplicationInfoImpl;
import com.intellij.openapi.ui.Messages;
import com.jetbrains.licenseServer.openapi.responses.*;
import com.jetbrains.licenseServer.openapi.util.ClientUtil;
import com.jetbrains.licenseServer.openapi.util.VerificationFailedException;

import java.io.IOException;

// Referenced classes of package com.intellij.ide.a.f:
//            q, z, ab, a, 
//            h, i, j, bb

public class LicenseServerSource extends ServerSource implements s {

    public static final String NAME = "License Server";
    protected int p;
    private final boolean q;
    private LicenseFile licenseFile;

    public LicenseServerSource(o o1, GeneralLicenseManager glm)
    {
        if(o1 == null)
        {
            throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] {
                "0", "com/intellij/ide/license/impl/LicenseServerSource", "<init>"
            }));
        } else
        {
            this(o1, glm, o1.h() * 1000, false);
            return;
        }
    }

    public LicenseServerSource(o o1, GeneralLicenseManager generalLicenseManager1, int i1, boolean flag)
    {
        if(o1 == null)
        {
            throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] {
                "0", "com/intellij/ide/license/impl/LicenseServerSource", "<init>"
            }));
        } else
        {
            super(o1, i1, generalLicenseManager1);
            q = flag;
            p = com.intellij.licensecommon.g.l.a(ApplicationInfoImpl.getShadowInstance().getMajorReleaseBuildDate().getTime());
            licenseFile = o1.e();
            return;
        }
    }

    protected String n()
    {
        return ClientUtil.getMachineId();
    }

    protected String k()
    {
        return "licensee";
    }

    protected String l()
    {
        return "maintenanceDue";
    }

    protected String m()
    {
        return "licenseType";
    }

    public void c()
    {
        ab ab1 = licenseFile.b();
        if(ab1 == null || ab1.v() == null)
        {
            return;
        } else
        {
            k = ab1.v();
            super.c();
            return;
        }
    }

    protected void b(ab ab1)
    {
        try
        {
            a(ab1);
        }
        catch(LicenseSaveException a1) { }
        super.b(ab1);
    }

    public void a(LicenseCorruptException e1)
        throws LicenseSaveException
    {
        licenseFile.a(e1);
    }

    public ab u()
    {
        ab ab1 = q();
        if(ab1 == null)
            return null;
        String s1 = ab1.v();
        String s2 = Messages.showInputDialog("Enter valid E-Mail address to send the activation code to", "Enter E-Mail Address", Messages.getQuestionIcon());
        if(s2 == null)
            return null;
        GetPermanentActivationResponse getpermanentactivationresponse;
        try
        {
            getpermanentactivationresponse = ClientUtil.obtainPermanentActivationCode(s1, o(), s2);
        }
        catch(VerificationFailedException verificationfailedexception)
        {
            a("Problem connecting to the server", (new StringBuilder()).append("Cannot obtain permanent ticket. Server protocol incompatible or hijacked: ").append(verificationfailedexception.getMessage()).toString());
            return null;
        }
        catch(IOException ioexception)
        {
            a("IO Problem", (new StringBuilder()).append("Cannot obtain permanent ticket due to connectivity problem: ").append(ioexception.getLocalizedMessage()).toString());
            return null;
        }
        ResponseCode responsecode = getpermanentactivationresponse.getResponseCode();
        if(responsecode == ResponseCode.ERROR)
        {
            a("Permanent Ticket Issue Refused", (new StringBuilder()).append("Server refused to issue the ticket: ").append(getpermanentactivationresponse.getMessage()).toString());
            return null;
        }
        String s3 = Messages.showInputDialog((new StringBuilder()).append("The activation code has been mailed to ").append(s2).append(". Paste it into the field below and press OK.").toString(), "Enter Activation Code", Messages.getQuestionIcon());
        if(s3 == null)
            return null;
        ObtainPermanentTicketResponse obtainpermanentticketresponse = a(k, s2, s3);
        if(obtainpermanentticketresponse == null)
            return null;
        if(obtainpermanentticketresponse.getResponseCode() == ResponseCode.ERROR)
        {
            a("Permanent Ticket Issue Refused", (new StringBuilder()).append("Server refused to issue the ticket: ").append(obtainpermanentticketresponse.getMessage()).toString());
            return null;
        } else
        {
            Messages.showInfoMessage("Permanent ticket successfully issued", "Permanent Ticket Received");
            h();
            long l1 = ab1.t();
            s();
            ab ab2 = a(s1, obtainpermanentticketresponse.getTicketId(), l1, obtainpermanentticketresponse.parseTicketProperties());
            ab2.c(true);
            b(ab2);
            c(ab2);
            return ab2;
        }
    }

    protected ServerSource.g_ a(ab ab1)
    {
        ProlongTicketResponse prolongticketresponse = ClientUtil.prolongTicket(ab1.v(), ab1.u(), o());
        if(prolongticketresponse.getResponseCode() == ResponseCode.OK) goto _L2; else goto _L1
_L1:
        q.g_.REFUSED;
        if(q.g_.REFUSED == null)
            throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] {
                "com/intellij/ide/license/impl/LicenseServerSource", "prolongServerLicense"
            }));
        return;
_L2:
        q.g_.OK;
        if(q.g_.OK == null)
            throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] {
                "com/intellij/ide/license/impl/LicenseServerSource", "prolongServerLicense"
            }));
        return;
        Object obj;
        obj;
        q.g_.REFUSED;
        if(q.g_.REFUSED == null)
            throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] {
                "com/intellij/ide/license/impl/LicenseServerSource", "prolongServerLicense"
            }));
        return;
        obj;
        q.g_.DISCONNECTED;
        if(q.g_.DISCONNECTED == null)
            throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] {
                "com/intellij/ide/license/impl/LicenseServerSource", "prolongServerLicense"
            }));
        return;
    }

    protected boolean b(String s1, String s2)
    {
        try
        {
            ReleaseTicketResponse releaseticketresponse = ClientUtil.releaseTicket(s1, s2, o());
            return releaseticketresponse.getResponseCode() == ResponseCode.OK;
        }
        catch(VerificationFailedException verificationfailedexception)
        {
            return false;
        }
        catch(IOException ioexception)
        {
            return false;
        }
    }

    static boolean d(String s1)
    {
        try
        {
            return ClientUtil.ping(s1).getResponseCode() == ResponseCode.OK;
        }
        catch(VerificationFailedException verificationfailedexception)
        {
            return false;
        }
        catch(IOException ioexception)
        {
            return false;
        }
    }

    protected ab c(String s1)
        throws h, i, j
    {
        ObtainTicketResponse obtainticketresponse = ClientUtil.obtainTicket(s1, o(), p(), p, q);
        if(obtainticketresponse.getResponseCode() != ResponseCode.OK) goto _L2; else goto _L1
_L1:
        ab ab1 = a(s1, obtainticketresponse.getTicketId(), obtainticketresponse.getProlongationPeriod(), obtainticketresponse.parseTicketProperties());
        ab1;
        if(ab1 == null)
            throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] {
                "com/intellij/ide/license/impl/LicenseServerSource", "obtainTicketFromServer"
            }));
        return;
_L2:
        try
        {
            throw new h(obtainticketresponse.getMessage());
        }
        catch(h h1)
        {
            throw new h(h1.getMessage());
        }
        catch(VerificationFailedException verificationfailedexception)
        {
            throw new j();
        }
        catch(IOException ioexception)
        {
            throw new i((new StringBuilder()).append("Cannot obtain ticket due to connectivity problem: ").append(ioexception.getClass().getName()).append(": ").append(ioexception.getMessage()).toString());
        }
    }

    protected ObtainPermanentTicketResponse a(String s1, String s2, String s3)
    {
        try
        {
            return ClientUtil.obtainPermanentTicket(s1, o(), p(), p, q, s2, s3);
        }
        catch(VerificationFailedException verificationfailedexception)
        {
            a("Problem connecting to the server", (new StringBuilder()).append("Cannot obtain permanent ticket. Server protocol incompatible or hijacked: ").append(verificationfailedexception.getMessage()).toString());
            return null;
        }
        catch(IOException ioexception)
        {
            a("IO Problem", (new StringBuilder()).append("Cannot obtain permanent ticket due to connectivity problem: ").append(ioexception.getLocalizedMessage()).toString());
        }
        return null;
    }

    public void v()
    {
        ab ab1 = q();
        if(ab1 == null)
            return;
        String s1 = ab1.v();
        boolean flag = b(s1, ab1.u());
        if(!flag)
        {
            a("No Valid Response from Server", "License server doesn't respond or refuses to return license to the pool");
            return;
        } else
        {
            a(s1, ab1.u(), true);
            s();
            b(s1, false);
            Messages.showInfoMessage("Permanent ticket successfully released. Floating license obtained.", "Permanent Ticket Released");
            return;
        }
    }
}
